package com.hgyc.mom.eam.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hgyc.mom.eam.mapper.EamEquipmentMapper;
import com.hgyc.mom.eam.entity.EamEquipment;
import com.hgyc.mom.eam.service.EamEquipmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import com.hgyc.mom.common.exception.BizException;
import org.springframework.util.CollectionUtils;

/**
 * 设备台账Service业务层实现
 *
 * @author fwj
 * @since 2025-08-10
 */
@Slf4j
@Service
public class EamEquipmentServiceImpl extends ServiceImpl<EamEquipmentMapper, EamEquipment> implements EamEquipmentService {

    @Override
    public void saveEquipment(EamEquipment eamEquipment) {
        // TODO 其他逻辑
        save(eamEquipment);
    }

    @Override
    public void updateEquipment(EamEquipment eamEquipment) {
        // TODO 其他逻辑
        updateById(eamEquipment);
    }

    @Override
    public void removeEquipment(List<Long> ids) {
        // TODO 其他逻辑
        removeByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String importData(List<EamEquipment> eamEquipmentList, boolean updateSupport) {
        if (eamEquipmentList == null || eamEquipmentList.isEmpty()) {
            throw new IllegalArgumentException("导入数据不能为空");
        }

        try {
            if (updateSupport) {
                // TODO 实现更新已有数据的导入逻辑
                return "更新导入成功，共导入 " + eamEquipmentList.size() + " 条数据";
            } else {
                // TODO 实现不更新已有数据的导入逻辑
                return "新增导入成功，共导入 " + eamEquipmentList.size() + " 条数据";
            }
        } catch (Exception e) {
            log.error("设备台账导入失败", e);
            throw new BizException("设备台账导入失败：" + e.getMessage());
        }
    }
}